﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BOMS.DBUtility;
using MySql.Data.MySqlClient;
using BOMS.Utility;
namespace BOMS.DAL
{
   public class DALUti
    {
         public static DataSet GetPageData(string sql, string orderby, int pageSize, int curPage, out int recordCount)
            {
                DataSet ds = new DataSet();
             if (DbHelper.DBType == ConstSet.DBTYPE_MSSQL)
             {   SqlParameter[] parms = new SqlParameter[5];
                (parms[0] = new SqlParameter("@sqlStr", SqlDbType.NVarChar, -1)).Value = sql;
                (parms[1] = new SqlParameter("@orderbyStr", SqlDbType.NVarChar, 30)).Value = orderby;
                (parms[2] = new SqlParameter("@pagesize", SqlDbType.Int)).Value = pageSize;
                (parms[3] = new SqlParameter("@curPage", SqlDbType.Int)).Value = curPage;
                (parms[4] = new SqlParameter("@rowcount", SqlDbType.Int)).Direction = ParameterDirection.Output;
                 ds = DbHelperSQL.RunProcedure("dbo.sp_FreePager", parms, "FPGOUT");
                recordCount = (int)parms[4].Value;
         }
             else if (DbHelper.DBType == ConstSet.DBTYPE_MYSQL)
             {
                 MySqlParameter[] parms = new MySqlParameter[5];
                 (parms[0] = new MySqlParameter("p_sqlStr", MySqlDbType.VarChar, -1)).Value = sql;
                 (parms[1] = new MySqlParameter("p_orderbyStr", MySqlDbType.VarChar, 30)).Value = orderby;
                 (parms[2] = new MySqlParameter("p_pagesize", MySqlDbType.Int32)).Value = pageSize;
                 (parms[3] = new MySqlParameter("p_curPage", MySqlDbType.Int32)).Value = curPage;
                 (parms[4] = new MySqlParameter("p_rowcount", MySqlDbType.Int32)).Direction = ParameterDirection.Output;
                  ds = DbHelperMySql.RunProcedure("sp_FreePager", parms, "FPGOUT");
                 recordCount = (int)parms[4].Value;
             }
             else
             {
                 recordCount = 0;
             }
                return ds;
            }
         public static string ImportEquipData(string ip, string mac, DateTime dtm, string xml)
         {

            // DbHelperSQL.connectionString = ConfigurationManager.ConnectionStrings["SQLConnString"].ConnectionString;
             //DbHelperSQL.ExecuteSql("exec sp_sub_LoadLogData '" + EquipMac + "','" + dtm.ToString() + "','" + xmlData + "'");
             if (DbHelper.DBType == ConstSet.DBTYPE_MSSQL)
             {
                 SqlParameter[] parms = new SqlParameter[4];
                 (parms[0] = new SqlParameter("@Mac", SqlDbType.NVarChar, 40)).Value = mac;
                 (parms[1] = new SqlParameter("@IP", SqlDbType.NVarChar, 40)).Value = ip;
                 (parms[2] = new SqlParameter("@dtm", SqlDbType.DateTime)).Value = dtm;
                 (parms[3] = new SqlParameter("@xmldata", SqlDbType.NVarChar, -1)).Value = xml;
                 SqlDataReader dr = DbHelperSQL.RunProcedure("sp_sub_LoadLogData", parms);
                 dr.Dispose();
                 dr.Close();
             }
             else if (DbHelper.DBType == ConstSet.DBTYPE_MYSQL)
             {
                 /* --暂未实现修改 --liangning2012-12-23.
                 MySqlParameter[] parms = new MySqlParameter[4];
                 (parms[0] = new MySqlParameter("@Mac", MySqlDbType.VarChar, 40)).Value = mac;
                 (parms[1] = new MySqlParameter("@IP", MySqlDbType.VarChar, 40)).Value = ip;
                 (parms[2] = new MySqlParameter("@dtm", MySqlDbType.DateTime)).Value = dtm;
                 (parms[3] = new MySqlParameter("@xmldata", MySqlDbType.VarChar, -1)).Value = xml;
                 MySqlDataReader dr = DbHelperMySql.RunProcedure("sp_sub_LoadLogData", parms);
                 dr.Dispose();
                 dr.Close();
                  * */
             }
             return "OK";
         }
    }
}
